package com.stu.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * @Author: MI
 * @Date: 2021/11/11/22:13
 * @Description:
 */
@Slf4j
@Api(tags = "数组接收")
@RestController
@RequestMapping("/arr")
public class ArrController {
    @ApiOperation(value = "测试接受数组", notes = "测试接受数组")
    @PostMapping("/")
    public JSONArray postBean(@RequestBody Arr arr) {
        System.out.println(arr);
        System.out.println("二维数组转字符串=>" + Arrays.deepToString(arr.getIds()));
        System.out.println(JSON.toJSONString(arr.getIds()));
        JSONArray objects = JSONArray.parseArray(JSON.toJSONString(arr.getIds()));
        return objects;
    }

    @Data
    static class Arr {
        private double[][] ids;
        private String name;

        @Override
        public String toString() {
            return ToStringBuilder.reflectionToString(this, ToStringStyle.NO_CLASS_NAME_STYLE);
        }
    }

    @ApiOperation(value = "测试提交二维数组", notes = "测试接受数组")
    @PostMapping("/double")
    public JSONArray arrs(@RequestBody double[][] ids) {

        System.out.println(ids);
        System.out.println(Arrays.deepToString(ids));
        JSONArray objects = new JSONArray();
        return objects;
    }

}
